19. Object Tracking

Optical Flow

Optical flow uses object features and an idea of perceived movement to track points and objects in consecutive frames.

Movement of a red ball being tracked over 5 frames

Movement of a red ball being tracked over 5 frames

To perform optical flow on a video or series of images, we'll first have to identify a set of feature points to track. We can use a Harris corner detector or other feature detector to get these. Then, at each time step or video frame, we track those points using optical flow.

OpenCV provides the function calcOpticalFlowPyrLK() for this purpose; it takes in three parameters: previous frame, previous feature points, and the next frame. And using only this knowledge, returns the predicted next points in the future frame.

In this way, we can track any moving object and determine how fast it's going and where it's likely to move next!

Examples

To see examples of tracking multiple cars and pedestrians, check out the OpenCV documentation.